import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
import webbrowser
import requests
import json
a = "123456"
class SheGongKu:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("行者长孙社工库 2.0(gui)(二改)")
        self.root.geometry("1200x800")
        self.root.configure(bg="#ffc0cb")
        
        self.style = ttk.Style()
        self.style.theme_use('clam')
        self.style.configure('TButton', font=('Arial', 12), padding=10)
        self.style.configure('TFrame', background="#f0f0f0")
        self.style.map('TButton', 
                      foreground=[('active', 'white'), ('!active', 'white')],
                      background=[('active', '#ffc0cb'), ('!active', '#ffc0cb')])
        
        messagebox.showinfo("欢迎", "行者长孙社工库欢迎你!\n以下是2.1版本的内容:由于二改添加了一些功能，请横屏使用")
        
        self.create_navbar()
        self.create_category_nav()
        self.show_category(3)
        
        self.root.mainloop()
    
    def create_navbar(self):
        self.navbar_frame = ttk.Frame(self.root)
        self.navbar_frame.pack(side="bottom", fill="x", padx=10, pady=10)
        
        ttk.Button(self.navbar_frame, text="功能", 
                 command=lambda: self.show_category(3)).pack(side="left", expand=True, padx=5)
        ttk.Button(self.navbar_frame, text="客服", 
                 command=self.show_customer_service).pack(side="left", expand=True, padx=5)
        ttk.Button(self.navbar_frame, text="我的", 
                 command=self.show_user_center).pack(side="left", expand=True, padx=5)
        ttk.Button(self.navbar_frame, text="会员模式", 
                 command=self.show_developer).pack(side="left", expand=True, padx=5)
        ttk.Button(self.navbar_frame, text="退出", 
                 command=self.root.quit).pack(side="left", expand=True, padx=5)
    def create_category_nav(self):
        self.category_frame = ttk.Frame(self.root)
        self.category_frame.pack(fill="x", padx=10, pady=10)
        
        ttk.Button(self.category_frame, text="网站相关(1-10)", 
                  command=lambda: self.show_category(1)).pack(side="left", expand=True, padx=5)
        ttk.Button(self.category_frame, text="查询功能(11-20)", 
                  command=lambda: self.show_category(2)).pack(side="left", expand=True, padx=5)
        ttk.Button(self.category_frame, text="其他杂项(21-31)", 
                  command=lambda: self.show_category(3)).pack(side="left", expand=True, padx=5)
    
    def show_category(self, category_num):
        for widget in self.root.winfo_children():
            if widget not in [self.category_frame, self.navbar_frame]:
                widget.destroy()
        
        canvas = tk.Canvas(self.root, bg="#ffc0cb", highlightthickness=0)
        scrollbar = ttk.Scrollbar(self.root, orient="vertical", command=canvas.yview)
        frame = ttk.Frame(canvas)
        
        frame.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
        canvas.create_window((0, 0), window=frame, anchor="nw")
        canvas.configure(yscrollcommand=scrollbar.set)
        
        canvas.pack(side="left", fill="both", expand=True, padx=10, pady=10)
        scrollbar.pack(side="right", fill="y")
        
        functions = self.get_functions_by_category(category_num)
        for func in functions:
            if "url" in func:
                btn = ttk.Button(
                    frame,
                    text=func["text"],
                    command=lambda u=func["url"]: webbrowser.open(u),
                    width=40
                )
            else:
                btn = ttk.Button(
                    frame,
                    text=func["text"],
                    command=func["action"],
                    width=40
                )
            btn.pack(pady=5, padx=10, fill="x")
    
    def get_functions_by_category(self, category_num):
        all_functions = [
            {"text": "1.4399小游戏", "url": "https://www.4399.com"},
            {"text": "2.学籍查询(教育部)", "url": "http://www.moe.gov.cn"},
            {"text": "3.中国新闻网", "url": "http://www.chinanews.com"},
            {"text": "4.贵州政务服务网", "url": "https://www.gzegn.gov.cn"},
            {"text": "5.山东政务服务网", "url": "http://www.shandong.gov.cn"},
            {"text": "6.在线工具箱", "url": "https://tool.lu"},
            {"text": "7.解锁会员", "action": lambda: messagebox.showinfo("会员", "联系客服QQ: 2214891426awa,暂时还没有会员功能")},
            {"text": "8.QQ官网", "url": "https://im.qq.com"},
            {"text": "9.快递查询", "url": "https://www.kuaidi100.com"},
            {"text": "10.猫咪图片", "url": "https://thecatapi.com"},
            {"text": "11.软件介绍", "action": lambda: messagebox.showinfo("介绍", "本软件来自行者长孙\n版本: 2.0\n所有功能合法合规")},
            {"text": "12.豆包AI", "url": "https://www.doubao.com"},
            {"text": "13.DeepSeek", "url": "https://www.deepseek.com"},
            {"text": "14.B站动画", "url": "https://www.bilibili.com"},
            {"text": "15.在线计算器", "url": "https://jisuanqi.supfree.net"},
            {"text": "16.快递单号查询", "url": "https://www.kuaidi100.com"},
            {"text": "17.动漫头像生成", "url": "https://www.avatarmaker.com"},
            {"text": "18.经纬度查询", "url": "https://www.gpsspg.com"},
            {"text": "19.手机号归属地", "action": self.show_phone_location},
            {"text": "20.高级工具集", "url": "https://tool.lu"},
            {"text": "21.官方QQ群", "action": lambda: messagebox.showinfo("QQ群", "群号: 616056460")},
            {"text": "22.抖音官网", "url": "https://www.douyin.com"},
            {"text": "23.快手官网", "url": "https://www.kuaishou.com"},
            {"text": "24.Unsplash美图", "url": "https://unsplash.com"},
            {"text": "25.腾讯微云", "url": "https://www.weiyun.com"},
            {"text": "26.QQ安全中心", "url": "https://aq.qq.com"},
            {"text": "27.上海政务服务", "url": "https://www.shanghai.gov.cn"},
            {"text": "28.江苏政务服务", "url": "http://www.jiangsu.gov.cn"},
            {"text": "29.北京政务服务", "url": "http://www.beijing.gov.cn"},
            {"text": "30.腾讯微云", "url": "https://www.weiyun.com"},
            {"text": "31.退出", "action": self.root.quit},
            {"text": "32.更多","action":lambda: messagebox.showinfo("提示","长孙行者工具箱™版权所有")}
        ]
        
        if category_num == 1:
            return all_functions[:10]
        elif category_num == 2:
            return all_functions[10:20]
        else:
            return all_functions[20:]
    
    def show_customer_service(self):
        service = simpledialog.askstring("客服", "请输入帮助获取选项:")
        if service == "帮助":
            choice = simpledialog.askstring("客服", "1.软件帮助\n2.转人工\n3.购买会员\n4.退出\n请输入数字:")
            if choice == "1":
                messagebox.showinfo("帮助", "行者长孙社工库2.0\n包含31个实用功能")
            elif choice == "2":
                messagebox.showinfo("人工客服", "QQ: 2214891426")
            elif choice == "3":
                messagebox.showinfo("会员", "联系QQ: 2214891426")
            elif choice > "4" or choice < "1" :
                messagebox.showinfo("错误","请输入有效的")
        else:
            messagebox.showinfo("提示", "请输入'帮助'获取选项")
    
    def show_user_center(self):
        messagebox.showinfo("我的", "用户中心\n版本: 2.1\n开发者: 行者长孙,二改作者:头像秀秀3月7")
    
    def show_developer(self):
        pwd = simpledialog.askstring("会员模式", "请输入密码:", show="#")
        if pwd == a:
            dev_window = tk.Toplevel(self.root)
            dev_window.title("会员选项")
            dev_window.geometry("1200x800")
            dev_window.configure(bg="#ffc0cb")
            
            ttk.Button(dev_window, text="手机号补全", 
                     command=self.show_phone_completion).pack(pady=10, padx=20, fill="x")
            ttk.Button(dev_window, text="身份证补全", 
                     command=self.show_id_card_completion).pack(pady=10, padx=20, fill="x")
            ttk.Button(dev_window, text="手机号归属地", 
                     command=self.show_phone_location).pack(pady=10, padx=20, fill="x")
            ttk.Button(dev_window, text="二要素验证", 
                     command=self.show_two_factor_auth).pack(pady=10, padx=20, fill="x")
            ttk.Button(dev_window, text="高级选项", 
                     command=lambda: messagebox.showinfo("高级选项", "啥都没有─=≡Σ((( つ•̀ω•́)つ喵呜")).pack(pady=10, padx=20, fill="x")
            ttk.Button(dev_window, text="关闭", 
                     command=dev_window.destroy).pack(pady=10, padx=20, fill="x")
        else:
            messagebox.showinfo("密码错误","请输入正确的密码")
    
    def show_phone_completion(self):
        phone_window = tk.Toplevel(self.root)
        phone_window.title("手机号补全查询")
        phone_window.geometry("1200x800")
        phone_window.configure(bg="#f0f0f0")
        
        frame = ttk.Frame(phone_window)
        frame.pack(pady=20, padx=20, fill="both", expand=True)
        
        ttk.Label(frame, text="手机号前缀(包含地区):例如111北京").pack(pady=5)
        prefix_entry = ttk.Entry(frame)
        prefix_entry.pack(pady=5, fill="x")
        
        ttk.Label(frame, text="手机号后缀:例如11").pack(pady=5)
        suffix_entry = ttk.Entry(frame)
        suffix_entry.pack(pady=5, fill="x")
        
        def query_phone():
            prefix = prefix_entry.get()
            suffix = suffix_entry.get()
            
            if not prefix or not suffix:
                messagebox.showerror("错误", "请输入完整的前缀和后缀")
                return
                
            try:
                api_url = f"https://sucyan.cfd/api/sjhbq.php?prefix={prefix}&houzhui={suffix}"
                response = requests.get(api_url)
                
                if response.status_code == 200:
                    messagebox.showinfo("查询结果", f"API返回结果:\n\n{response.text}")
                else:
                    messagebox.showerror("错误", f"请求失败，状态码: {response.status_code}")
            except Exception as e:
                messagebox.showerror("错误", f"请求过程中发生错误:\n\n{str(e)}")
        
        ttk.Button(frame, text="查询", command=query_phone).pack(pady=20, fill="x")
        ttk.Button(frame, text="关闭", command=phone_window.destroy).pack(fill="x")
    
    def show_id_card_completion(self):
        id_window = tk.Toplevel(self.root)
        id_window.title("身份证补全查询")
        id_window.geometry("1200x800")
        id_window.configure(bg="#ffc0cb")
        
        frame = ttk.Frame(id_window)
        frame.pack(pady=20, padx=20, fill="both", expand=True)
        
        ttk.Label(frame, text="身份证前14位:").pack(pady=5)
        sfz_entry = ttk.Entry(frame)
        sfz_entry.pack(pady=5, fill="x")
        
        ttk.Label(frame, text="性别(男/女):").pack(pady=5)
        xb_var = tk.StringVar(value="男")
        ttk.Radiobutton(frame, text="男", variable=xb_var, value="男").pack()
        ttk.Radiobutton(frame, text="女", variable=xb_var, value="女").pack()
        
        def query_id():
            sfz = sfz_entry.get()
            xb = xb_var.get()
            
            if not sfz or len(sfz) != 14:
                messagebox.showerror("错误", "请输入14位身份证号码")
                return
                
            try:
                api_url = f"https://sucyan.cfd/api/sfzbq.php?sfz={sfz}&xb={xb}"
                response = requests.get(api_url)
                
                if response.status_code == 200:
                    messagebox.showinfo("查询结果", f"API返回结果:\n\n{response.text}")
                else:
                    messagebox.showerror("错误", f"请求失败，状态码: {response.status_code}")
            except Exception as e:
                messagebox.showerror("错误", f"请求过程中发生错误:\n\n{str(e)}")
        
        ttk.Button(frame, text="查询", command=query_id).pack(pady=20, fill="x")
        ttk.Button(frame, text="关闭", command=id_window.destroy).pack(fill="x")
    
    def show_phone_location(self):
        phone_window = tk.Toplevel(self.root)
        phone_window.title("手机号归属地查询")
        phone_window.geometry("1600x1000")
        phone_window.configure(bg="#ffc0cb")
        
        frame = ttk.Frame(phone_window)
        frame.pack(pady=20, padx=20, fill="both", expand=True)
        
        ttk.Label(frame, text="请输入手机号码:").pack(pady=5)
        phone_entry = ttk.Entry(frame)
        phone_entry.pack(pady=5, fill="x")
        
        result_text = tk.Text(frame, height=10, wrap=tk.WORD)
        result_text.pack(pady=10, fill="both", expand=True)
        
        def query_location():
            phone = phone_entry.get()
            if not phone or len(phone) != 11:
                messagebox.showerror("错误", "请输入11位有效手机号码")
                return
                
            try:
                api_url = f"https://sucyan.cfd/api/phone.php?phone={phone}"
                response = requests.get(api_url)
                
                if response.status_code == 200:
                    data = response.json()
                    result_text.delete(1.0, tk.END)
                    if isinstance(data, dict):
                        for key, value in data.items():
                            result_text.insert(tk.END, f"{key}: {value}\n")
                    else:
                        result_text.insert(tk.END, data)
                else:
                    messagebox.showerror("错误", f"请求失败，状态码: {response.status_code}")
            except Exception as e:
                messagebox.showerror("错误", f"请求过程中发生错误:\n\n{str(e)}")
        
        btn_frame = ttk.Frame(frame)
        btn_frame.pack(fill="x", pady=10)
        
        ttk.Button(btn_frame, text="查询", command=query_location).pack(side="left", expand=True)
        ttk.Button(btn_frame, text="清空", command=lambda: result_text.delete(1.0, tk.END)).pack(side="left", expand=True)
        ttk.Button(btn_frame, text="关闭", command=phone_window.destroy).pack(side="left", expand=True)
    
    def show_two_factor_auth(self):
        auth_window = tk.Toplevel(self.root)
        auth_window.title("二要素验证")
        auth_window.geometry("1200x800")
        auth_window.configure(bg="#ffc0cb")
        
        frame = ttk.Frame(auth_window)
        frame.pack(pady=20, padx=20, fill="both", expand=True)
        
        ttk.Label(frame, text="姓名:").pack(pady=5)
        name_entry = ttk.Entry(frame)
        name_entry.pack(pady=5, fill="x")
        
        ttk.Label(frame, text="证件号(18位数字):").pack(pady=5)
        id_entry = ttk.Entry(frame)
        id_entry.pack(pady=5, fill="x")
        
        result_text = tk.Text(frame, height=10, wrap=tk.WORD)
        result_text.pack(pady=10, fill="both", expand=True)
        
        def query_auth():
            name = name_entry.get()
            id_num = id_entry.get()
            
            if not name or not id_num:
                messagebox.showerror("错误", "请输入姓名和证件号")
                return
                
            if len(id_num) != 18 or not id_num.isdigit():
                messagebox.showerror("错误", "证件号必须是18位数字")
                return
                
            try:
                api_url = f"https://sucyan.cfd/api/2ys1.php?name={name}&id={id_num}"
                response = requests.get(api_url)
                
                if response.status_code == 200:
                    data = response.json()
                    result_text.delete(1.0, tk.END)
                    if isinstance(data, dict):
                        for key, value in data.items():
                            result_text.insert(tk.END, f"{key}: {value}\n")
                    else:
                        result_text.insert(tk.END, data)
                else:
                    messagebox.showerror("错误", f"请求失败，状态码: {response.status_code}")
            except Exception as e:
                messagebox.showerror("错误", f"请求过程中发生错误:\n\n{str(e)}")
        
        btn_frame = ttk.Frame(frame)
        btn_frame.pack(fill="x", pady=10)
        
        ttk.Button(btn_frame, text="验证", command=query_auth).pack(side="left", expand=True)
        ttk.Button(btn_frame, text="清空", command=lambda: result_text.delete(1.0, tk.END)).pack(side="left", expand=True)
        ttk.Button(btn_frame, text="关闭", command=auth_window.destroy).pack(side="left", expand=True)

if __name__ == "__main__":
    app = SheGongKu()